/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package rad.Java.MotelPlus.Class;

import java.sql.Time;
import rad.Java.MotelPlus.Views.AptView;

/**
 *
 * @author rogerio
 */
public class Timmer extends Thread
{
    private AptView btnApt;
    long start;
    private boolean threadDone = true;

    public Timmer(AptView btn)
    {
        this.btnApt = btn;
        start = System.currentTimeMillis();
    }

    public void done()
    {
        threadDone = false;
        this.btnApt.setText(this.btnApt.getNameApt());
    }

    public void setStart(long value)
    {
        this.start = value;
    }

    public long getUnixEpochStart()
    {
        return start/1000;
    }

    @Override
    public void run()
    {
        while(threadDone)
        {
            // FIXME: Gambiarra, adicionar 3 horas para zerar cronometro 3 * 60 * 60 * 1000
            Time time = new Time(System.currentTimeMillis() - start + 10800000);
 

            this.btnApt.setText("<html>"+this.btnApt.getNameApt()+"<br>"+time.toString()+"</html>");
            
            try
            {
                Thread.sleep(1000);
            }
            catch(InterruptedException e)
            {
            }
        }
    }
}
